﻿// See https://aka.ms/new-console-template for more information
using System.Linq;

Console.WriteLine("Hello, World!");
//switch模式匹配
var condition = 2;
string a = "123";

List<string> tempList = new List<string>() { "123", "456", "789" };

var result = a switch
{
    "1" => 1,
};



Action action = condition switch
{
    0 => () =>
    {
        Console.WriteLine(123);
    }
    ,
    1 => () =>
    {
        Console.WriteLine(456);
    }
    ,
    2 => () =>
    {
        Console.WriteLine(789);
    }
};
action.Invoke();

string switchmethod_1(int par) => par switch
{
    1 => "1",
    2 => "2",
    3 => "3",
    < 0 => "5+",
    (> 5) and (< 10) => "7",
    _ => "4",
};
string switchmethod_2(Order order) => order switch
{
    { items: 1, cost: > 10 } => "一块钱",
    { items: 2, cost: > 10 } => "两块钱",
    { items: 3, cost: > 10 } => "三块钱",
};
string switchmethod_3(Order order) => order switch
{
    (1, > 10) => "一块钱",//注意此处括号不同
    (2, > 10) => "两块钱",
    { items: 3, cost: > 10 } => "三块钱",
};

string switchmethod_4(string par) => par switch
{
    string obj when obj.Contains("123") => "123",
    "456" => "456",
};

record Order(int items, decimal cost);